package com.zy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.Vo.InboundVo;
import com.zy.Vo.PagetInboundVo;
import com.zy.mapper.InboundMapper;
import com.zy.pojo.Inbound;
import com.zy.service.InboundService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service("inboundService")
public class InboundServiceImpl implements InboundService {
    @Resource
    private InboundMapper inboundMapper;
    @Override
    public List<Inbound> getInboundList() {
        return inboundMapper.getInboundList();
    }

    @Override
    public PagetInboundVo getPageInboundList(Integer pageSize, Integer pageNo, InboundVo inboundVo) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(inboundVo.getName()),"name",inboundVo.getName())
                .eq(inboundVo.getPoId()!=null,"po_id",inboundVo.getPoId())
                .eq(inboundVo.getQuantity()!=null,"quantity",inboundVo.getQuantity())
                .gt(inboundVo.getInboundDateg()!=null,"inbound_date",inboundVo.getInboundDateg())
                .lt(inboundVo.getInboundDatel()!=null,"inbound_date",inboundVo.getInboundDatel());
        List<Inbound> list = inboundMapper.getInboundPageList(page,queryWrapper);
        System.out.println(page.getTotal()+"+++++++++++++++++++++++++");
        return new PagetInboundVo(list,page.getTotal());
    }

    @Override
    public void getInboundAdd(Inbound inbound) {
    inboundMapper.insert(inbound);
    }

    @Override
    public void getInboundUpdate(Inbound inbound) {
        inboundMapper.updateById(inbound);
    }

    @Override
    public void getInboundDelete(Integer id) {
        inboundMapper.deleteById(id);
    }

    @Override
    public List<Inbound> getInboundPoList() {
        return inboundMapper.getInboundDelList();
    }

    @Override
    public void getInboundDeAdd(Inbound inbound) {
        inboundMapper.getInbound(inbound);
    }
}
